package com.bq.gametrade.ui.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.bq.gametrade.R;

/**
 * Created by Feel on 2017/1/12.
 */

public class ExitLoginDialog extends DialogFragment implements View.OnClickListener {

    private Button btnExit, btnReturm;
    private ImageView ivClose;

    public interface OnExitLoginListener {
        void onExitClick();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_exitlogin, null);
        initView(view);
        getDialog().setCanceledOnTouchOutside(false);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = 1.0f;
        window.setGravity(Gravity.CENTER);
        window.setAttributes(lp);
        getDialog().show();
        return view;
    }

    private void initView(View view) {
        btnExit = (Button) view.findViewById(R.id.btn_exit);
        btnExit.setOnClickListener(this);
        btnReturm = (Button) view.findViewById(R.id.btn_return);
        btnReturm.setOnClickListener(this);
        ivClose = (ImageView) view.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_exit:
                dismiss();
                OnExitLoginListener loginListener = (OnExitLoginListener) getActivity();
                loginListener.onExitClick();
                break;
            case R.id.btn_return:
                dismiss();
                break;
            case R.id.iv_close:
                dismiss();
                break;
        }
    }
}
